import axios from 'axios'
import { ElMessage } from 'element-plus'
let instance = axios.create({
    baseURL:"/admin",
    timeout: 5000  //设置超时事件
})
instance.interceptors.request.use((config)=>{
    let token =localStorage.getItem("token");
    if(token){
        config.headers.token=token
    }
    return config;
})
instance.interceptors.response.use((res)=>{
    if(res.data?.data?.token){
        localStorage.setItem("token",res.data.data.token);
    }
    ElMessage({
        message: res.data.message,
        type: res.data.code==="200"?"success":"error",
      })
    return res.data;
})
export default instance;